<template>
  <div>
    <div>
      <div class="building_recommend_title">
        <div>为您精选</div>
        <div class="building_recommend_select">
          <div @click="changeSelectName(index)" :class="{theme_color:getForYourUrl === index}"
               v-for="(item,index) in selectName">{{item.title}}
          </div>
        </div>
      </div>
      <!--<div>-->
        <!--<div class="building_recommend">-->
          <!--<div @click="goLinkTo(item.url)" v-if="getForYourUrl === 0" v-for="item in buildHouse">-->
            <!--<img :src="item.image" alt="">-->
            <!--<div class="build_title">-->
              <!--<span>{{item.title}}</span>-->
            <!--</div>-->
          <!--</div>-->
          <!--<div @click="goLinkTo(item.url)"  v-for="item in buildHouse" v-if="getForYourUrl === 1">-->
            <!--<img :src="item.image" alt="">-->
            <!--<div class="build_title">-->
              <!--<span>{{item.title}}</span>-->
            <!--</div>-->
          <!--</div>-->
          <!--&lt;!&ndash;<div>&ndash;&gt;-->
            <!--&lt;!&ndash;<img src="../assets/image/recommend.png" alt="">&ndash;&gt;-->
            <!--&lt;!&ndash;<div class="build_title">&ndash;&gt;-->
              <!--&lt;!&ndash;<span>海景公寓</span>&ndash;&gt;-->
            <!--&lt;!&ndash;</div>&ndash;&gt;-->
          <!--&lt;!&ndash;</div>&ndash;&gt;-->
        <!--</div>-->
      <!--</div>-->
      <!--<div class="building_list">-->
      <keep-alive>
        <build-list v-if="getForYourUrl === 0 && listContent.data" :newHouseList="listContent.data"></build-list>
      </keep-alive>
      <keep-alive>
        <house-list v-if="getForYourUrl === 1 && listContent.data" :houseListData="listContent.data"></house-list>
      </keep-alive>
      <keep-alive>
        <renting-list v-if="getForYourUrl === 2 && listContent.data" :houseListData="listContent.data"></renting-list>
      </keep-alive>
          <!--<div v-if="getForYourUrl === 2">-->
            <!--该地区暂时没有租房房源-->
          <!--</div>-->
      <!--</div>-->
      <!--<div class="building_look_more" v-show="listContent.last_page !== 0">-->
        <!--<div @click="lookMoreHouse" v-show="formData.page !== listContent.last_page && getForYourUrl !== 2">查看更多</div>-->
      <!--</div>-->
      <div class="building_look_more">
        <div @click="lookMoreHouse">查看更多</div>
      </div>
    </div>
  </div>
</template>

<script>
  import {buildList, houseList,indexBuildHouse} from '../axios/api';
  import BuildList from './listComponents/NewHouseList';
  import HouseList from './listComponents/ListContent';
  import RentingList from './listComponents/RentingList';
import {getCityName} from '../assets/js/cache';

  export default {
    name: 'BuildingRecommend',
    data() {
      return {
        selectName: [
          {title: '新房'},
          {title: '二手房'},
          {title: '租房'}
        ],
        formData: {
          city_code: getCityName().CODE,
          page: 1
        },
        listContent: {},
        isMoreShow: false,
        buildHouse:[]
      }
    },
    created() {

    },
    mounted(){
      this.getList();
    },
    methods: {
      // 精选图片点击跳转
      goLinkTo(url){
        let that = this;
        if (that.getForYourUrl === 0) {
          that.$router.push(url)
        } else if (that.getForYourUrl === 1) {
          that.$router.push(url);
        } else if (that.getForYourUrl === 2) {
          that.$router.push(url);
        } else {

        }
      },
      //查看更多
      lookMoreHouse() {
        let that = this;
        if (that.getForYourUrl === 0) {
          that.$router.push({name:'LookBuild'})
        } else if (that.getForYourUrl === 1) {
          that.$router.push({name:'TwoHouse'})
        } else if (that.getForYourUrl === 2) {
          that.$router.push({name:'RentingHouse'})
        } else {

        }
      },
      changeSelectName(index) {
        this.$store.commit('setForYourUrl', index);
        this.getList();
      },
      getList() {
        let that = this;
        that.listContent = {};
        that.formData.page = 1;
        this.getListData();
      },
      getListData() {
        let that = this;
        that.formData.city_code = getCityName().CODE;
        if (that.getForYourUrl === 0) {
          buildList(that.formData).then(res => {
            that.listContent = res.data;
            console.log(res);
          }).catch(err => {
            console.log(err);
          });
          indexBuildHouse(1).then(res=>{
            this.buildHouse = res.data;
            console.log(res,'--------');
          }).catch(err=>{
            console.log(err)
          })
        } else if (that.getForYourUrl === 1) {
          houseList(that.formData).then(res => {
            that.listContent = res.data;
          }).catch(err => {
            console.log(err);
          });
          indexBuildHouse(2).then(res=>{
            this.buildHouse = res.data;
            console.log(res,'--------');
          }).catch(err=>{
            console.log(err)
          })
        } else if (that.getForYourUrl === 2) {

        } else {

        }
      }
    },
    computed: {
      getForYourUrl() {
        return this.$store.getters.getForYourUrl;
      }
    },
    components: {
      BuildList,
      HouseList,
      RentingList
    }
  }
</script>

<style scoped>

  .building_recommend_title {
    display: flex;
    justify-content: space-between;
    padding: 10px;
  }

  .building_recommend {
    display: -webkit-box;
    overflow-x: scroll;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 0 10px 10px 10px;
  }

  .building_recommend_select {
    display: flex;
  }

  .building_recommend_select > div {
    margin: 5px;
    font-size: 0.8rem;
  }

  .building_recommend::-webkit-scrollbar {
    display: none;
  }

  .building_recommend > div {
    width: 6rem;
    height: 6rem;
    margin: 0 0 10px 10px;
    position: relative;
  }

  .building_recommend > div:nth-child(1) {
    margin-left: 0;
  }

  .building_recommend > div img {
    width: 100%;
    height: 100%;
  }

  .building_recommend .build_title {
    height: 6rem;
    width: 6rem;
    position: absolute;
    text-align: center;
    top: 0;
    left: 0;
    background-color: rgba(116, 118, 120, 0.2);
    /*line-height: 6rem;*/
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .building_recommend .build_title > span {
    text-align: center;
    /*height: 100%;*/
    color: #ffffff;
    width: 4em;
  }

  .building_list {

  }

  .building_list > div {
    border-top: 1px solid #eeeeee;
    padding: 10px;
    height: 5.5rem;
    display: flex;
  }

  .building_list img {
    height: 5.5rem;
    width: 6rem;
  }

  .building_list > div:nth-child(1) {
    border: none;
  }

  .building_list_content {
    flex: 1;
    margin-left: 10px;
    position: relative;
  }

  .building_list_content .title {
    font-size: 1.2rem;
    color: #333;
  }

  .building_list_content .content {
    height: 1.2rem;
    line-height: 1.2rem;
    display: flex;
    justify-content: space-between;
  }

  .building_list_content .content .left {
    font-size: 0.8rem;
    color: #999;
  }

  .building_list_content .content .icon-ditu {
    color: #e6191e;
    font-size: 0.8rem;
  }

  .building_list_content .content .money_pay {
    color: #e6191e;
    font-weight: bold;
  }

  .building_list_content .housing {
    display: flex;
    justify-content: space-between;
    color: #999;
    font-size: 0.8rem;
  }

  .building_list_content .label {
    position: absolute;
    bottom: 1px;
    left: 0;
  }

  .building_list_content .label > span {
    padding: 3px 5px;
    font-size: 0.8rem;
  }

  .building_list_content .label > span:nth-child(1) {
    background-color: #ffebea;
    color: #e6191e;
  }

  .building_list_content .label > span:nth-child(2) {
    background-color: #dff1fd;
    color: #42abff;
  }

  .building_list_content .label > span:nth-child(3) {
    background-color: #fde9dd;
    color: #fa6609;
  }

  .building_look_more {
    height: 3rem;
    margin: 10px 0;
  }

  .building_look_more > div {
    margin: 0 auto;
    height: 3rem;
    width: 10rem;
    line-height: 3rem;
    text-align: center;
    color: #b9b8b8;
    background-color: #f8f8f8;
  }
</style>
